const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
//每次更新build都清空/dist文件
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
module.exports = {
    // entry: './src/index.js', //当文件输入

    //多文件输入
    entry: {
        app: './src/index.js',
        print: './src/print.js'
    },
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        rules: [{
            test: /\.css$/,
            use: [
                "style-loader",
                "css-loader"
            ]
        },
            {
                test: /\.(png|svg|jpg|gif)$/,
                use: [{
                    loader:'file-loader',
                    options: {
                        name: "[hash:10].[ext]",//name是指原始名称
                        outputPath: "images/",
                    },
                }
                ],

            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: ["file-loader"],
            },
            {
                test: /\.(csv|tsv)$/,
                use: ["csv-loader"],
            },
            {
                test: /\.xml$/,
                use: ["xml-loader"],
            },
            {
                test: /\.txt$/,
                use: "raw-loader",
            },
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: "Webpack App",
            // filename: "admin.html",
            // template: "src/index.html",

            // filename {String } 默认为 index.html, 这个是指定你生成的index.html的路径和名称;
            // template { String } 默认为 '', 有时候你想要自己写生成的index.html文件,这个属性就是指定你的模版路径的.
            // favion {String} 指定你生成index.html的图标, 当然如果你使用了template, 这个属性也可以不用了


        }),
        new CleanWebpackPlugin({
                   cleanAfterEveryBuildPatterns: ["dist"], // 这个是非必填的
       }),
    ]
}
